package com.account.book.controller;


import cn.hutool.core.lang.tree.Tree;
import com.account.book.common.response.BaseResult;
import com.account.book.common.response.ResultUtils;
import com.account.book.request.CategoryBaseReqVo;
import com.account.book.response.CategoryQueryResVo;
import com.account.book.response.CategoryResVo;
import com.account.book.service.CategoryBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author liang-hw
 * @className CategoryBaseController
 * @description 账本基础分类接口
 * @date 2023/12/05 09:08:41
 */
@Api(tags = {"账本基础分类接口"})
@RestController
@RequestMapping("/api/category/base")
public class CategoryBaseController {

    @Autowired
    private CategoryBaseService categoryBaseService;

    /**
     * @param @param categoryQueryReqVo
     * @return @return {@link BaseResult }<{@link List }<{@link CategoryResVo }>>
     * @author liang-hw
     * @description 查询分类
     * @date 2023/11/09 13:29:05
     */
    @ApiOperation(value = "查询基础分类", notes = "查询基础分类")
    @GetMapping("/findCategoryBaseList")
    public BaseResult<List<Tree<String>>> findCategoryBaseList(@RequestParam("type") Integer type) {
        List<Tree<String>> findCategoryBaseList = categoryBaseService.findCategoryBaseList(type);
        return ResultUtils.success(findCategoryBaseList);
    }

    /**
     * @param @param  categoryReqVo
     * @param request
     * @return @return {@link BaseResult }
     * @author liang-hw
     * @description 新建账本分类
     * @date 2023/11/09 13:26:29
     */
    @ApiOperation(value = "新建账本分类", notes = "新建账本分类")
    @PostMapping("/save")
    public BaseResult save(@RequestParam("file") MultipartFile uploadFile, @RequestParam("name") String name, @RequestParam("parentId") String parentId, @RequestParam("type") Integer type) {
        CategoryBaseReqVo categoryBaseReqVo = new CategoryBaseReqVo();
        categoryBaseReqVo.setName(name);
        categoryBaseReqVo.setParentId(parentId);
        categoryBaseReqVo.setType(type);
        categoryBaseService.save(categoryBaseReqVo, uploadFile);
        return ResultUtils.success();
    }

    /**
     * @param @param categoryBaseReqVo
     * @return @return {@link BaseResult }<{@link CategoryQueryResVo }>
     * @author liang-hw
     * @description 更新分类
     * @date 2023/12/05 09:46:06
     */
    @ApiOperation(value = "更新分类", notes = "更新分类")
    @PostMapping("/updateCategory")
    public BaseResult updateCategory(@RequestBody CategoryBaseReqVo categoryBaseReqVo) {
        categoryBaseService.updateCategory(categoryBaseReqVo);
        return ResultUtils.success();
    }

    /**
     * @param @param categoryId
     * @param bookId
     * @return @return {@link BaseResult }
     * @author liang-hw
     * @description 移除基础分类
     * @date 2023/11/09 13:44:43
     */
    @ApiOperation(value = "移除基础分类", notes = "移除基础分类")
    @GetMapping("/remove")
    public BaseResult remove(@RequestParam("type") Integer type, @RequestParam("name") String name) {
        categoryBaseService.remove(type, name);
        return ResultUtils.success();
    }
}
